import { Component } from '@angular/core';
import {RedisService} from '../../services/redis.service';
import {NzColDirective, NzRowDirective} from 'ng-zorro-antd/grid';
import {NzButtonComponent} from 'ng-zorro-antd/button';
import {NzListComponent, NzListItemComponent} from 'ng-zorro-antd/list';
import { NzInputModule } from 'ng-zorro-antd/input';
import { FormsModule } from '@angular/forms';
import {NzSpaceComponent, NzSpaceItemDirective} from 'ng-zorro-antd/space';
import {NzTooltipDirective} from 'ng-zorro-antd/tooltip';
import {NzMessageService} from 'ng-zorro-antd/message';

@Component({
  selector: 'app-bloom',
  standalone: true,
  imports: [
    NzRowDirective,
    NzColDirective,
    NzButtonComponent,
    NzListComponent,
    NzListItemComponent,
    NzInputModule,
    FormsModule,
    NzSpaceComponent,
    NzTooltipDirective,
    NzSpaceItemDirective
  ],
  templateUrl: './bloom.component.html',
  styleUrl: './bloom.component.css'
})
export class BloomComponent {

  constructor(private redisService: RedisService,
              private message: NzMessageService) {}

  username: String="";
  password: String="";

  searchLoading = false;
  editDelayLoading = false;
  editLockLoading = false;

  search(){
    this.searchLoading = true;
    this.redisService.search(this.username).subscribe(res => {
      this.searchLoading = false
      // @ts-ignore
      if(res.code == 0){
        // @ts-ignore
        this.message.success(JSON.stringify(res.data))
      }else{
        // @ts-ignore
        this.message.success(JSON.stringify(res.msg))
      }

    })
  }

  edit_delay(){
    this.editDelayLoading = true;
    this.redisService.editDelay({"username":this.username, "password":this.password}).subscribe(res => {
      this.editDelayLoading = false;
    })
  }

  edit_lock(){
    this.editLockLoading = true;
    this.redisService.editLock({"username":this.username, "password":this.password}).subscribe(res => {
      this.editLockLoading = false;
    })
  }

}
